home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Fmt C Library Procedures Fmt
-
-
-
- _________________________________________________________________
-
- NNAAMMEE
- Fmt_Convert - Package for converting data from one byte-
- order/alignment format to another.
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<ffmmtt..hh>>
-
- int
- FFmmtt__CCoonnvveerrtt(_c_o_n_t_e_n_t_s, _i_n_F_o_r_m_a_t, _i_n_S_i_z_e_P_t_r, _i_n_B_u_f_f_e_r, _o_u_t_F_o_r_m_a_t, _o_u_t_S_i_z_e_P_t_r, _o_u_t_B_u_f_f_e_r)
-
- int
- FFmmtt__SSiizzee(_c_o_n_t_e_n_t_s, _i_n_F_o_r_m_a_t, _i_n_S_i_z_e_P_t_r, _o_u_t_F_o_r_m_a_t, _o_u_t_S_i_z_e_P_t_r)
-
- AARRGGUUMMEENNTTSS
- char *_c_o_n_t_e_n_t_s (in) String describing con-
- tents of _i_n_B_u_f_f_e_r (see
- below).
-
- Fmt_Format _i_n_F_o_r_m_a_t (in) Byte-order/alignment
- format of data in
- _i_n_B_u_f_f_e_r.
-
- int *_i_n_S_i_z_e_P_t_r (in/out) Points to size of
- _i_n_B_u_f_f_e_r. Upon return
- *_i_n_S_i_z_e_P_t_r is the number
- of bytes actually used.
-
- char *_i_n_B_u_f_f_e_r (in) Data to be converted.
-
- Fmt_Format _o_u_t_F_o_r_m_a_t (in) Byte-order/alignment
- format of data in _o_u_t_-
- _B_u_f_f_e_r.
-
- int *_o_u_t_S_i_z_e_P_t_r (in/out) Points to size of _o_u_t_-
- _B_u_f_f_e_r. Upon return
- *_o_u_t_S_i_z_e_P_t_r contains the
- number of bytes actually
- used. For FFmmtt__SSiizzee this
- is strictly an out
- parameter.
-
- char *_o_u_t_B_u_f_f_e_r (in) Converted data.
-
- _________________________________________________________________
-
-
- DDEESSCCRRIIPPTTIIOONN
- FFmmtt__CCoonnvveerrtt converts data between different byte-
- order/alignment formats. Typically this is done between dif-
- ferent machine types, but it can be used to convert between
- two compilers that align data differently. _I_n_F_o_r_m_a_t speci-
- fies the byte-order/alignment format of the data in
-
-
-
- Sprite v.1.0 Printed: May 29, 1990 1
-
-
-
-
-
-
- Fmt C Library Procedures Fmt
-
-
-
- _i_n_B_u_f_f_e_r, and _o_u_t_F_o_r_m_a_t specifies the byte-order/alignment
- format of the data in _o_u_t_B_u_f_f_e_r after the conversion. The
- data to be converted is read from _i_n_B_u_f_f_e_r and the converted
- data is written to _o_u_t_B_u_f_f_e_r. The parameter _i_n_S_i_z_e_P_t_r
- points to the size of the input buffer. When FFmmtt__CCoonnvveerrtt
- returns *_i_n_S_i_z_e_P_t_r contains the number of bytes that were
- actually used. It is possible for less than the entire
- buffer to be converted depending upon the _c_o_n_t_e_n_t_s string.
- See below for more details on _c_o_n_t_e_n_t_s. The parameter _o_u_t_-
- _S_i_z_e_P_t_r points to the size of the output buffer. When
- FFmmtt__CCoonnvveerrtt returns *_o_u_t_S_i_z_e_P_t_r contains the number of bytes
- actually used.
-
- FFmmtt__SSiizzee computes the minimum size output buffer needed con-
- verting the data at described by the _c_o_n_t_e_n_t_s string The
- result is returned in *_o_u_t_S_i_z_e_P_t_r. This size can then be
- passed to FFmmtt__CCoonnvveerrtt (assuming that the format and contents
- parameters remain the same).
-
- The legal values for the format parameters are defined in
- fmt.h. They are as follows:
-
- FFMMTT__6688KK__FFOORRMMAATT
- The byte-order/alignment format of code compiled by Gcc
- for Motorola 680x0 machines. Treating an integer as an
- array of 4 bytes (char buf[4]), buf[0] contains the
- most significant byte. Halfwords, words and doublewords
- are aligned on even boundaries. The alignment of struc-
- tures and unions equals the most restrictive alignment
- of one of their members, such that they are at least
- aligned on an even boundary. The size of structures
- and unions is a multiple of their alignment.
-
- FFMMTT__VVAAXX__FFOORRMMAATT
- The byte-order/alignment format of the Vax. Treating
- an integer as an array of 4 bytes (char buf[4]), buf[0]
- contains the least significant byte. Halfwords are
- aligned on even boundaries. Words and doublewords are
- aligned on word boundaries. The alignment of structures
- and unions equals the most restrictive alignment of one
- of their members. The size of structures and unions is
- a multiple of their alignment.
-
- FFMMTT__SSPPUURR__FFOORRMMAATT
- The byte-order/alignment format of code compiled by Gcc
- for the Spur. Treating an integer as an array of 4
- bytes (char buf[4]), buf[0] contains the least signifi-
- cant byte. Halfwords are aligned on even boundaries,
- words are aligned on quad boundaries, and doublewords
- are aligned on oct boundaries. The alignment of struc-
- tures and unions equals the most restrictive alignment
- of one of their members, such that they are at least
-
-
-
- Sprite v.1.0 Printed: May 29, 1990 2
-
-
-
-
-
-
- Fmt C Library Procedures Fmt
-
-
-
- aligned on a quad boundary. The size of structures and
- unions is a multiple of their alignment.
-
- FFMMTT__SSPPAARRCC__FFOORRMMAATT
- The byte-order/alignment format of code compiled by the
- SunOS compiler for the Sparc architecture. Treating an
- integer as an array of 4 bytes (char buf[4]), buf[0]
- contains the most significant byte. Halfwords are
- aligned on even boundaries, words are aligned on quad
- boundaries, and doublewords are aligned on oct boun-
- daries. The alignment of structures and unions equals
- the most restrictive alignment of one of their members.
- The size of structures and unions is a multiple of
- their alignment.
-
- FFMMTT__MMIIPPSS__FFOORRMMAATT
- The byte-order/alignment format of code compiled by the
- Ultrix compiler for the Mips (DecStation3100) architec-
- ture. Treating an integer as an array of 4 bytes (char
- buf[4]), buf[0] contains the least significant byte.
- Halfwords are aligned on even boundaries, words are
- aligned on quad boundaries, and doublewords are aligned
- on oct boundaries. The alignment of structures and
- unions equals the most restrictive alignment of one of
- their members. The size of structures and unions is a
- multiple of their alignment. |
-
- FFMMTT__MMYY__FFOORRMMAATT ||
- This format is set to the format of the machine on |
- which the code is running. This relieves the program |
- that is using the FFmmtt package from having to decide |
- with format is appropriate for a particular machine.
-
- The _c_o_n_t_e_n_t_s parameter is used to describe the data types
- that comprise the input buffer. The buffer can contain
- bytes, halfwords (2 bytes), words (4 bytes), doublewords (8
- bytes), structures, and unions. These data types are
- represented in the contents string using the following char-
- acters.
-
- bb One byte.
-
- hh One halfword (2 bytes).
-
- ww One word (4 bytes).
-
- dd One double word (8 bytes).
-
- {{ The start of a structure.
-
- }} The end of a structure.
-
-
-
-
- Sprite v.1.0 Printed: May 29, 1990 3
-
-
-
-
-
-
- Fmt C Library Procedures Fmt
-
-
-
- (( The start of a union. The '((' must be followed by a
- discriminant that indicates which of the components of
- the union is to be converted. The discriminant is a
- decimal number that gives the index of the component,
- starting at 0.
-
- )) The end of a union.
-
- 00-99* A decimal number following a data type (byte, halfword,
- word, doubleword, structure, or union) indicates that
- the data type is repeated the given number of times.
- For instance, the string "w5" means that the input con-
- tains 5 consecutive words. There is an ambiguity that
- arises when describing the contents of a union. "w5"
- can either refer to one component of 5 words, or to 5
- components of one word each. The abiguity is resolved
- by having "w5" refer to one component of 5 words, and
- "wwwww" refer to 5 components of one word. Similarly,
- "w*" refers to one component (see next paragraph for
- description of the '*' character).
-
- ** A '**' means 1 or more repetitions of the previous data
- type. The number of repetitions is determined by the
- amount of data remaining in the input buffer. Care must
- be taken if the '**' character is anything but the last
- character in the string. Certain formats place con-
- straints on the sizes of unions and structures that may
- cause the '**' character to give unwanted results. For
- example, consider a structure consisting of a word fol-
- lowed by a byte that is defined as "{wb*}". In the
- Spur format "b*" will refer to 4 bytes, while in the
- 68K format it will refer to 2 bytes.
-
-
- The following are examples of input data types and content
- strings.
-
- _D_a_t_a:
-
- int foo[5];
-
- _C_o_n_t_e_n_t _s_t_r_i_n_g:
-
- "w5" or "w*" or "wwwww"
-
- _D_a_t_a:
-
-
- struct flea {
- char mite;
- int spider;
- int worm;
-
-
-
- Sprite v.1.0 Printed: May 29, 1990 4
-
-
-
-
-
-
- Fmt C Library Procedures Fmt
-
-
-
- short moth;
- short mosquito;
- short beetle;
- int fly[5];
- char gnat[50];
- };
-
- _C_o_n_t_e_n_t _s_t_r_i_n_g:
-
- "{bwwh3w5b*}"
-
- _D_a_t_a:
-
-
- struct foo {
- char bar;
- int baz;
- union {
- short quux;
- double cow;
- } dog[6];
- };
-
- _C_o_n_t_e_n_t _s_t_r_i_n_g:
-
- "{bw(0hd)6}" or "{bw(0hd)*}" if "quux" is the component
- of "dog" to be converted,
- or,
- "{bw(1hd)6}" or "{bw(1hd)*}" if "cow" is the component
- of "dog" to be converted.
-
-
- RREETTUURRNN VVAALLUUEESS
- The following return codes are defined in fmt.h:
-
- FFMMTT__OOKK (0)
- Procedure completed properly
-
- FFMMTT__CCOONNTTEENNTT__EERRRROORR
- The _c_o_n_t_e_n_t_s parameter contained an error.
-
- FFMMTT__IINNPPUUTT__TTOOOO__SSMMAALLLL
- The input buffer was smaller than indicated by _c_o_n_-
- _t_e_n_t_s.
-
- FFMMTT__OOUUTTPPUUTT__TTOOOO__SSMMAALLLL
- The output buffer was too small to hold the converted
- data. This is only returned by FFmmtt__CCoonnvveerrtt.
-
- FFMMTT__IILLLLEEGGAALL__FFOORRMMAATT
- One of the format parameters was illegal.
-
-
-
-
- Sprite v.1.0 Printed: May 29, 1990 5
-
-
-
-
-
-
- Fmt C Library Procedures Fmt
-
-
-
- KKEEYYWWOORRDDSS
- byte-order, byte-swap, alignment, data conversion
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sprite v.1.0 Printed: May 29, 1990 6
-
-
-
-